Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

391 changes: 68 additions & 323 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified out/production/courseScala/main/Helper$.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/courseScala/main/Helper.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/courseScala/main/LexAnalizer.class
Binary file not shown.
Binary file modified out/production/courseScala/main/Main$delayedInit$body.class
Binary file not shown.
6 changes: 1 addition & 5 deletions qwer.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DATA SEGMENT
77DATA SEGMENT
decem1 DD .028
decem2 DQ 0.025
decem4 DQ -0.025
Expand All @@ -8,8 +8,6 @@ DATA SEGMENT
des2 DQ 12345678
des3 DQ -12345678
DATA ENDS


CODE SEGMENT
finit
fadd dword ptr decem2[eax]
Expand All @@ -32,7 +30,5 @@ CODE SEGMENT
Fcom st(7)
Fadd dword ptr fs:decem1[esi]
Faddp st(2), st(0)


CODE ENDS
END
75 changes: 59 additions & 16 deletions src/main/Helper.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package main

import java.io.FileNotFoundException

import scala.collection.mutable
import scala.collection.mutable.ListBuffer

Expand All @@ -13,33 +15,74 @@ object Helper {
def isDiv(ch:Char):Boolean = dividers.contains(ch)

val machineComm = List("finit","fcom","fadd","faddp")
val directives = List("END", "SEGMENT", "ENDS", "DQ", "DD")
val directives = List("end", "segment", "ends", "dq", "dd")
val regGeneral32 = List("eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp")
val typeOfIdent = List("dword","qword")
val ptr = "ptr"
val st = "st"
val regSegment = List("fs"," gs", "cs", "ss", "ds", "es")
val lexemType = List( "Machine command","Directive","User identif","Dec const",
"32b register","Type of ident","Operator of type def",
"Segment reg","Single lexem","Dec const")
def checkWhat(map:mutable.Map[Int,ListBuffer[String]]):Unit ={

case class ErrorT(str:String,row:Int, fl:Boolean)
def checkWhat(tempTok:String):String ={
tempTok match {
case tempTok if dividers.contains(tempTok.toLowerCase) => baseDelim().setName()
case tempTok if regSegment.contains(tempTok.toLowerCase) => baseRegSegment().setName()
case tempTok if typeOfIdent.contains(tempTok.toLowerCase) => baseTypeofIdent().setName()
case tempTok if regGeneral32.contains(tempTok.toLowerCase) => baseReg32().setName()
case tempTok if directives.contains(tempTok.toLowerCase) => baseDirect().setName()
case tempTok if machineComm.contains(tempTok.toLowerCase) => baseMachineCom().setName()
case tempTok if ptr.contains(tempTok.toLowerCase) => baseOperofDef().setName()
case tempTok if st.contains(tempTok.toLowerCase) => baseCopReg().setName()
case tempTok if checkInt(tempTok)=> baseDec().setName()
case _ => baseUserId().setName()
}
}
def printTable(k:Int):Unit={

}

def checkInt(t:String):Boolean = t.matches(floatPat)


//val intPat = """0|(\+|-)?[1-9][0-9]*[a-z]?"""
val floatPat = """((-)?[0-9]*[a-z]?\.[0-9]*)|0|(\+|-)?[1-9][0-9]*[a-z]?"""
val floatPat = """([^[a-zA-Z]]*(-)?[0-9]*[dD]?\.[0-9]*)|0|(-)?[1-9][0-9]*[dD]?"""
val operatorPat = """\[|]|\(|\)|\,|:|!="""
val idPat = """[a-zA-Z][0-9a-zA-Z]*"""
val tokenPat = (floatPat + "|" + idPat + "|" + operatorPat).r
var Error = false
val idPat = """[0-9]*?[a-zA-Z][0-9a-zA-Z]*"""
val tokenPat = (idPat + "|" +floatPat+ "|" + operatorPat).r

var Error = false
var LexicalList = new ListBuffer[List[mainToken]]
var SyntaxList = new ListBuffer[tokenSyntax]
case class mainToken(row:Int, rowIndex:Int, token:String)
case class tokenSyntax(name:mainToken,function:String)
trait BaseLexem
case class baseDelim() extends BaseLexem {
def setName():String = "Single lexem"
}
case class baseRegSegment() extends BaseLexem {
def setName():String = "Segment reg"
}
case class baseTypeofIdent() extends BaseLexem {
def setName():String = "Type of ident"
}
case class baseReg32() extends BaseLexem {
def setName():String = "32b register"
}
case class baseDirect() extends BaseLexem {
def setName():String = "Directive"
}
case class baseMachineCom() extends BaseLexem {
def setName():String = "Machine command"
}
case class baseOperofDef() extends BaseLexem {
def setName():String ="Operator of type def"
}
case class baseDec() extends BaseLexem {
def setName():String ="Dec constant"
}
case class baseCopReg() extends BaseLexem {
def setName():String ="Coproces reg"
}
case class baseUserId() extends BaseLexem {
def setName():String ="User ident"
}

case class rowToken(row:Int,rowIndex:Int,token:String)
trait BaseLexem{
def print()
def len()
}
}
70 changes: 53 additions & 17 deletions src/main/LexAnalizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,70 @@ import java.io.FileNotFoundException

import main.Helper._

import scala.collection.mutable._
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.Source

class LexAnalizer {
def initMap(namefile: String):Unit = {
def initMap(namefile: String): Unit = {
try {
var tempList = new ListBuffer[rowToken]
var lst = new ListBuffer[List[rowToken]]
var tempList = new ListBuffer[mainToken]

var row =1
var rowInd =1
var row = 1
var rowInd = 1

for (line <- Source.fromFile(namefile).getLines) {

tempList.clear()
var tokens = tokenPat.findAllIn(line)

rowInd=1
for(next <- tokens){
tempList += rowToken(row,rowInd,next)
rowInd+=1
rowInd = 1
for (next <- tokens) {
tempList += mainToken(row, rowInd, next)
rowInd += 1
}
row+=1
lst += tempList.toList

row += 1
LexicalList += tempList.toList
}
// for(listBuf<- lst){println(listBuf)}
} catch {
case ex: FileNotFoundException => Error = true
println("Missing file exception")
}
case ex: FileNotFoundException => Error = true
println("Missing file exception")
}
}

def printLexic(): Unit = {
var si = 0
var forIdent = new ErrorT("",0,false)
var flag = false
for(listBuf<- LexicalList){
si = 0
for(go<-listBuf) {
if (si==0){
printf(" ------------------------ROW#%s#------------------------\n", go.row)
print("\tLEXEM\t\t\t\tLENGTH\t\t\tTYPE\n")
}

var tmp1 = go.token

if(tmp1.length<4)printf("\t%s\t\t\t\t\t", tmp1)
else if(tmp1.length>7) printf("\t%s\t\t\t", tmp1)
else printf("\t%s\t\t\t\t", tmp1)

print(tmp1.length)

var base = checkWhat(tmp1)
if(base.equals("User ident")&&((tmp1.length>8)|| isNum(tmp1.charAt(0)))) {
flag = true
forIdent = new ErrorT(tmp1,go.row, true)
}
printf("\t\t\t%s\n", base)
si+=1
SyntaxList+=tokenSyntax(go,base)
}
if (flag==true) {
Console.out.println( Console.RED + "bad identification in " +forIdent.row+" row name " +forIdent.str+ Console.RESET )
flag = false
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ object Main extends App {

val an = new LexAnalizer()
an.initMap(Console.readLine()+".asm")
// an.analize()
//an.printLexic()
}
13 changes: 13 additions & 0 deletions src/main/SyntaxAnalizer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import scala.collection.mutable
import scala.collection.mutable._

class SyntaxAnalizer {
trait SynTable

val Table = new ListBuffer[ListBuffer[String]](
("User ident","Directive"),
("User ident","Directive","Directive"))

}