c# - Compiler help (transition matrix) -



c# - Compiler help (transition matrix) -

i have matrix transitions in programming language. lets have next code:

if(x=0) { x=10; }

when start reading '(' store word "if", after loss character '(' . how can maintain parenthesis?? far code looks this:

for (int = 0; <code.length ; i++) { char currentchar= code[i]; (int j = 0; j < chars.length; j++) { if (currentchar == '(') { column= 15; i--; } }

but loops , stays on reading '(' , wont go on reading rest of code.

the reason code looping because moving before '(' , loop moving '('. loop infinitely.

example:

when = 2: currentchar == '(' column = 15 i = i-1 becomes 1 loop iteration finishes i = + 1 becomes 2; when = 2:...

your code description above not create possible me provide solution dilemma however. can tell causing infinite loop.

edit: best can provide know in general token collecting. need buffer current token saved off when reach delimiter. here rough illustration (again, without improve clarification can little help):

using system; using system.collections.generic; using system.text; public class programme { public static void main(){ var code = @"if(x=0) { x=10; }"; var tokens = new list<string>(); var token = new stringbuilder(); for(int = 0; < code.length; i++) { char currentchar = code[i]; if(currentchar == '(') { tokens.add(token.tostring()); token = new stringbuilder(); } // checks other tokens else { token.append(code[i]); } } foreach(var tkn in tokens) { console.writeline(tkn); } } }

c# compiler-construction

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -