escaping - Problem when reading backslash in Prolog -


I am writing a laser in Prologue which will be used as part of the functional language interpreter. Example of language allows expression such as two \ x = x + 2; yes. What I want to do for this type of input is "Return":

  [tokLet, toklambda, tokvar (x), tokEq, tokvar (x), tokplus, toknumber (2), TokSColon]  

And the problem is, the prologue seems to ignore the character \ and the line written above except tokLambda "Return" .

One way to solve this is to add a second backslash before / after each event in the program code (because everything is fine if I change the original input to let \\ x = X + 2 ; ) but I really do not like it.

Any thoughts?

Edit: If anyone should have such problems, then how do I solve it?

  Main (file): - Open ( < / Pre> 

you get the string let \ x = x + 2; ?

  • If this is your program program: Yes, you will have to double backslabs.
  • If it is from an external file: How do you read it from there? The prediction can be especially backslash Let me explain.

I was inspired by that problem and wrote some code, which should be portable for all prol implementations:

 % redlines (-line) %% reads a row from the current input, then the line is returned as a list of atoms of one-letter atoms, except for the new characters.% Returned line does not tell you that the end of input% Or have not reached or not. Readline (line): - 'Readley : Reading ([], Riwarsed) reverse (line Riwarsed). Reedlain: read (currently Out): - Get_char (C) 'Reedlain: Append (C CONTENT Out). 'Redline: append' (- 1, current, current): -! 'Readline: Append' ('\ n', current, running): -! 'Readline: Append' (C, Content, Line): - 'Readline: Reading' ([C | current], line).  

I tried to do it, and he worked for me.

Of course, as explained in the question, you read_line_to_codes / 2 .


Comments