Skip to content

Commit

Permalink
Merge pull request #16 from CarmenMarroquin/main
Browse files Browse the repository at this point in the history
Issue 2 fixes
  • Loading branch information
luisespino authored Jan 9, 2025
2 parents 1ec28da + 14a477d commit 9d2b56d
Show file tree
Hide file tree
Showing 10 changed files with 1,009 additions and 16 deletions.
7 changes: 5 additions & 2 deletions fases/fase3/parser/Templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const main = (data) => `
module parser
implicit none
character(len=:), allocatable, private :: input
integer, private :: savePoint, lexemeStart, cursor
integer, private :: lexemeStart, cursor
interface toStr
module procedure intToStr
Expand Down Expand Up @@ -254,6 +254,7 @@ export const rule = (data) => `
integer :: count, min_reps, max_reps, tempi
integer :: i
logical :: pivote
integer :: savePoint
savePoint = cursor
${data.expr}
Expand All @@ -266,6 +267,7 @@ export const rule = (data) => `
integer :: count, min_reps, max_reps
integer :: i, tempi
logical :: pivote
integer :: savePoint
savePoint = cursor
${data.expr.replace(/if\(\.not\./g, "if(")}
Expand All @@ -278,6 +280,7 @@ export const rule = (data) => `
integer :: count, min_reps, max_reps, tempi
integer :: i
logical :: pivote
integer :: savePoint
savePoint = cursor
${getReplaceKleene(data)}
Expand Down Expand Up @@ -308,7 +311,7 @@ function getReplaceKleene(data) {
* @returns
*/
export const election = (data) => `
do i = 0, ${data.exprs.length-1}
do i = 0, ${data.exprs.length}
select case(i)
${data.exprs
.map(
Expand Down
13 changes: 7 additions & 6 deletions fases/fase3/parser/compiler/Translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ export default class FortranTranslator {
*/
visitRegla(node) {

console.log("\nVisit Regla: ")
console.log("\n-----------------------\n| Visit Regla |\n-----------------------")
console.dir(node)
console.dir(node.expr.exprs)
console.dir(this.actionReturnTypes)
this.currentRule = node.id;
this.currentChoice = 0;
this.conteoAccion = 0;

if (node.start) this.translatingStart = true;


const ruleTranslation = Template.rule({
id: node.id,
returnType: getReturnType(
Expand All @@ -85,10 +87,9 @@ export default class FortranTranslator {
.filter((expr) => expr instanceof CST.Pluck)
.map((label, j) => {
const expr = label.labeledExpr.annotatedExpr.expr;
console.log(election)
return `${
expr instanceof CST.Identificador
? getReturnType(getActionId(expr.id, election.action ? i : 0), this.actionReturnTypes)
? getReturnType(getActionId(expr.id, 0), this.actionReturnTypes)
: "character(len=:), allocatable"
} :: expr_${i}_${j}`;
})
Expand All @@ -107,7 +108,7 @@ export default class FortranTranslator {
* @this {Visitor}
*/
visitOpciones(node) {
console.log("\Visit Opciones: ") // <3
console.log("\nVisit Opciones: ") // <3
console.dir(node)
return Template.election({
exprs: node.exprs.map((expr) => {
Expand All @@ -123,7 +124,7 @@ export default class FortranTranslator {
* @this {Visitor}
*/
visitUnion(node) {
console.log("\nVisit Union: ") // <3
console.log("\n-----------------------\n| Visit Union |\n-----------------------")
console.dir(node)
const matchExprs = node.exprs.filter((expr) => expr instanceof CST.Pluck);
console.log(`\tMatchExprs:`)
Expand Down Expand Up @@ -701,7 +702,7 @@ export default class FortranTranslator {
paramDeclarations: Object.entries(node.params).map(
([label, ruleId]) =>
`${getReturnType(
getActionId(ruleId, this.currentChoice),
getActionId(ruleId, 0),
this.actionReturnTypes
)} :: ${label}`
),
Expand Down
6 changes: 3 additions & 3 deletions test/test1/exec
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gfortran -c parser.f90
gfortran -c test.f90
gfortran parser.o test.o -o test
gfortran -g -c parser.f90
gfortran -g -c test.f90
gfortran -g parser.o test.o -o test
./test input.txt
2 changes: 1 addition & 1 deletion test/test1/input.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2 + 2 * 3
2+3*4+5*6
Loading

0 comments on commit 9d2b56d

Please sign in to comment.