Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors committed Jun 23, 2015
2 parents 9d1079d + cb3a2fb commit 9b29383
Show file tree
Hide file tree
Showing 26 changed files with 1,269 additions and 1,120 deletions.
1 change: 1 addition & 0 deletions openmodelica/omcc/.gitignore
@@ -0,0 +1 @@
OpenModelicaHome.mo
29 changes: 15 additions & 14 deletions openmodelica/omcc/GenerateParser.mos
Expand Up @@ -2,20 +2,21 @@ setCommandLineOptions({"+g=MetaModelica","+d=rml"});
loadFile("Types.mo");
loadFile("Absyn.mo");

//loadFile("../../../Compiler/FrontEnd/Absyn.mo");
loadFile("../../../Compiler/Util/Error.mo");
loadFile("../../../Compiler/Util/ErrorExt.mo");
loadFile("../../../Compiler/FrontEnd/Dump.mo");
loadFile("../../../Compiler/Util/Print.mo");
loadFile("../../../Compiler/Util/Flags.mo");
loadFile("../../../Compiler/Global/Global.mo");
loadFile("../../../Compiler/Util/Config.mo");
loadFile("../../../Compiler/Util/Debug.mo");
loadFile("../../../Compiler/Util/List.mo");
loadFile("../../../Compiler/Util/Settings.mo");
loadFile("../../../Compiler/Util/Corba.mo");
loadFile("../../../Compiler/Util/Util.mo");
loadFile("../../../Compiler/Util/System.mo");
compilerSources := "../../../OMCompiler/Compiler/";

loadFile(compilerSources + "Util/Error.mo");
loadFile(compilerSources + "Util/ErrorExt.mo");
loadFile(compilerSources + "FrontEnd/Dump.mo");
loadFile(compilerSources + "Util/Print.mo");
loadFile(compilerSources + "Util/Flags.mo");
loadFile(compilerSources + "Global/Global.mo");
loadFile(compilerSources + "Util/Config.mo");
loadFile(compilerSources + "Util/Debug.mo");
loadFile(compilerSources + "Util/List.mo");
loadFile(compilerSources + "Util/Settings.mo");
loadFile(compilerSources + "Util/Corba.mo");
loadFile(compilerSources + "Util/Util.mo");
loadFile(compilerSources + "Util/System.mo");
loadFile("TokenModelica.mo");
loadFile("LexTableModelica.mo");
loadFile("LexerCodeModelica.mo");
Expand Down
95 changes: 62 additions & 33 deletions openmodelica/omcc/Lexer.mo
Expand Up @@ -7,7 +7,7 @@ import System;
import List;
import Util;

import arrayGet = MetaModelica.Dangerous.arrayGetNoBoundsChecking;
import arrayGet = MetaModelica.Dangerous.arrayGetNoBoundsChecking; // Bounds checked with debug=true
import stringGet = MetaModelica.Dangerous.stringGetNoBoundsChecking;
import MetaModelica.Dangerous.listReverseInPlace;

Expand Down Expand Up @@ -121,7 +121,7 @@ function consume
input Integer inNumStates;
input String fileName;
output list<OMCCTypes.Token> resToken;
output Integer bkBuffer := 0;
output Integer bkBuffer = 0;
output Integer mm_startSt;
output Integer mm_currSt,mm_pos,mm_sPos,mm_ePos,mm_linenr,lineNrStart;
output Integer buffer;
Expand Down Expand Up @@ -198,7 +198,16 @@ algorithm

(act, mm_currSt, mm_pos, mm_sPos, mm_linenr, buffer, bkBuffer, states, numStates) := findRule(lexTables, fileContents, mm_currSt, mm_pos, mm_sPos, mm_ePos, mm_linenr, buffer, bkBuffer, states, numStates);

if (debug==true) then
print("\nFound rule: " + String(act));
end if;

(tok,mm_startSt,buffer2) := LexerCode.action(act,mm_startSt,mm_currSt,mm_pos,mm_sPos,mm_ePos,mm_linenr,lineNrStart,buffer,debug,fileName,fileContents);

if (debug==true) then
print("\nDid action");
end if;

mm_currSt := mm_startSt;
arrayUpdate(states,1,mm_startSt);
numStates := 1;
Expand Down Expand Up @@ -282,6 +291,10 @@ algorithm
list<Integer> restBuff;
case (_,true)
equation
if debug then
checkArray(mm_accept,stCmp,sourceInfo());
checkArray(mm_acclist,lp,sourceInfo());
end if;
lp = arrayGet(mm_accept,stCmp);
act = arrayGet(mm_acclist,lp);
then (act, mm_currSt, mm_pos, mm_sPos, mm_linenr, buffer, bkBuffer, states, numStates);
Expand All @@ -296,6 +309,9 @@ algorithm
mm_sPos = mm_ePos;
mm_linenr = mm_linenr-1;
end if;
if debug then
checkArray(states,numStates,sourceInfo());
end if;
mm_currSt = arrayGet(states,numStates);
numStates = numStates - 1;
(act, mm_currSt, mm_pos, mm_sPos, mm_linenr, buffer, bkBuffer, states, numStates) = findRule(lexTables, fileContents, mm_currSt, mm_pos, mm_sPos, mm_ePos, mm_linenr, buffer, bkBuffer, states, numStates);
Expand All @@ -310,9 +326,9 @@ function evalState
input Integer c;
output Integer new_state;
output Integer new_c;
protected
Integer cState1:=cState;
Integer c1:=c;
protected
Integer cState1=cState;
Integer c1=c;
array<Integer> mm_accept,mm_ec,mm_meta,mm_base,mm_def,mm_nxt,mm_chk,mm_acclist;
Integer val,val2,chk;
algorithm
Expand Down Expand Up @@ -376,9 +392,9 @@ function printBuffer2
input list<Integer> inList;
input String cBuff;
output String outList;
protected
list<Integer> inList1:=inList;
String cBuff1:=cBuff;
protected
list<Integer> inList1=inList;
String cBuff1=cBuff;
algorithm
(outList) := match(inList,cBuff)
local
Expand All @@ -399,8 +415,8 @@ end printBuffer2;
function printBuffer
input list<Integer> inList;
output String outList;
protected
list<Integer> inList1:=inList;
protected
list<Integer> inList1=inList;
Integer c;
algorithm
outList := "";
Expand All @@ -411,29 +427,42 @@ algorithm
end printBuffer;

function printStack
input list<Integer> inList;
input String cBuff;
output String outList;
protected
list<Integer> inList1:=inList;
String cBuff1:=cBuff;
algorithm
(outList) := match(inList,cBuff)
local
Integer c;
String new,tout;
list<Integer> rest;
case ({},_)
then (cBuff1);
else
equation
c::rest = inList1;
new = cBuff1 + "|" + intString(c);
(tout) = printStack(rest,new);
then (tout);
end match;
end printStack;

input list<Integer> inList;
input String cBuff;
output String outList;
protected
list<Integer> inList1=inList;
String cBuff1=cBuff;
algorithm
(outList) := match(inList,cBuff)
local
Integer c;
String new,tout;
list<Integer> rest;
case ({},_)
then (cBuff1);
else
equation
c::rest = inList1;
new = cBuff1 + "|" + intString(c);
(tout) = printStack(rest,new);
then (tout);
end match;
end printStack;

function checkArray<T>
input array<T> arr;
input Integer index;
input SourceInfo info;
protected
String filename;
Integer lineStart;
algorithm
if index<1 or index>arrayLength(arr) then
SOURCEINFO(fileName=filename, lineNumberStart=lineStart) := info;
print("\n[" + filename + ":" + String(lineStart) + "]: checkArray failed: arrayLength="+String(arrayLength(arr))+" index=" + String(index) + "\n");
fail();
end if;
end checkArray;

end Lexer;
13 changes: 7 additions & 6 deletions openmodelica/omcc/LexerCode.tmo
@@ -1,5 +1,5 @@
encapsulated package %LexerCode% // Generated %time%
/*
/*
Template for Lexer Code
replace keywords:
%LexerCode
Expand Down Expand Up @@ -41,17 +41,18 @@ algorithm
act2 := act;
bufferRet := 0;
(token) := match (act)
local
local
OMCCTypes.Token tok;
%caseAction%
else
equation
tok = OMCCTypes.TOKEN("",act,fileContents,mm_pos,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1);
print("\nLexer unknown rule, action="+String(act)+"\n");
tok = OMCCTypes.TOKEN("",act,fileContents,mm_pos-buffer,buffer,lineNrStart,mm_ePos+1,mm_linenr,mm_sPos+1);
print(OMCCTypes.printToken(tok));
then (OMCCTypes.noToken);
then fail();
end match;
end action;
end action;

%epilogue%

end %LexerCode%;

0 comments on commit 9b29383

Please sign in to comment.